No. If the file does not open an IOException is thrown and then caught by the outer catch{} block
Usually data is much more complicated than the data for the example program. But the program shows the outer logic that is needed to read most files. Sometimes the data in a file represents something other than a primitive Java type. For example, word processor files contain many bytes that encode fonts, page formats, and special symbols.
The DataOutputStream
and DataInputStream
classes have
several methods for reading and writing single bytes.
Here are two of them:
DataOutputStream: public final void writeByte(int b) throws IOException DataInputStream: public final int readUnsignedByte() throws IOException
writeByte()
writes the least significant byte
of its int
argument to the output stream.
readUnsignedByte()
reads a byte from the input
stream and puts it in the least significant byte of its
return value.